package com.captain.special.链表;

import com.captain.leetcode.链表.ListNode;

import java.util.List;

/**
 * Des:
 *
 * @author XL
 * @Date 2022/3/22 11:48
 */
public class 两两交换链表中的节点24 {

    public ListNode swapPairs(ListNode head) {

        //1 2 3 4
        ListNode dummy = new ListNode(-1, head);
        ListNode pre = dummy;
        ListNode temp;
        while (head != null && head.next != null) {
            temp = head.next.next;
            pre.next= head.next;
            pre.next.next = head;
            head.next = temp;
            pre = head;
            head = head.next;
        }

        return dummy.next;
    }
}
